package com.nblog.controller.admin;

import com.jfinal.kit.Ret;
import com.jfinal.upload.UploadFile;
import com.nblog.annotation.ControllerBind;
@ControllerBind(controllerKey="/admin/ueditor")
public class UeditorController extends BaseControlller {
    public void upload(){
        if ("config".equals(getPara("action"))) {
            render("/static/ueditor/jsp/config.json");
            return;
        }
        UploadFile file = getFile("upfile","images");
        String fileName = file.getFileName();
        String[] typeArr = fileName.split("\\.");
        String orig = file.getOriginalFileName();
        long size = file.getFile().length();
        Ret ret = Ret.create("state", "SUCCESS")
                .set("url", this.getRequest().getContextPath()+"/uploads/images/"+fileName)
                .set("title", fileName)
                .set("original", orig)  
                .set("type", "."+typeArr[1])
                .set("size", size);
        renderJson(ret);
    }
}
